package com.IO.Object;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;

/**
 * name：zhangwang
 * time：2025/3/12 13:51
 */
//序列化多条数据
public class ObjectOutputTestList  {
    public static void main(String[] args)throws  Exception {
        //创建用户对象
        User user1 = new User("熊凯kl;l;ml;m",89656);
        User user2 = new User("熊凯kl;l;ml;m",89656);
        User user3 = new User("熊凯kl;l;ml;m",89656);
        User user4 = new User("熊凯kl;l;ml;m",89656);
        //把对象值放到一个集合中去
        ArrayList<User> users = new ArrayList<>();
        Collections.addAll(users,user2,user1,user3,user4);
        //创建序列化流对象
        ObjectOutputStream ops = new ObjectOutputStream(new FileOutputStream("d.txt"));
        //把对象写到文件中
        ops.writeObject(users);
        //释放资源
        ops.close();
    }
}
